package com.test.daidai.main;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;

import com.test.ddaidai.MyApp;
import com.test.ddaidai.main_more.SuggestionFeedbackActivity;
import com.test.ddaidai.main_more.UpdateGesturePasswordActivity;
import com.test.ddaidai.main_more.UpdateLoginPasswordActivity;
import com.test.ddaidai_android.activity.R;

public class MoreFragment extends Fragment implements OnClickListener {

	TextView btn_more_updateloginpassword,btn_more_updategesturepassword,btn_more_suggestionback;
	ImageButton btn_guest_switch;
	SharedPreferences sp;
	boolean geust_switch;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		
		View v = inflater.inflate(R.layout.fragment_more_main, null);
		
		sp = getActivity().getSharedPreferences(MyApp.DDAIDAI_SP,Context.MODE_PRIVATE);
		
		btn_more_updateloginpassword = (TextView) v.findViewById(R.id.btn_more_updateloginpassword);
		btn_more_updateloginpassword.setOnClickListener(this);
		btn_more_updategesturepassword = (TextView) v.findViewById(R.id.btn_more_updategesturepassword);
		btn_more_updategesturepassword.setOnClickListener(this);
		btn_more_suggestionback = (TextView) v.findViewById(R.id.btn_more_suggestionback);
		btn_more_suggestionback.setOnClickListener(this);
		
		btn_guest_switch = (ImageButton) v.findViewById(R.id.btn_guest_switch);
		geust_switch = sp.getBoolean("guest_switch",false);
		
		btn_guest_switch
		.setImageResource(geust_switch == true ? R.drawable.guesture_on
				: R.drawable.guesture_off);
		
		btn_guest_switch.setOnClickListener(this);
		return v;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btn_more_updateloginpassword:
			startActivity(new Intent(this.getActivity(),UpdateLoginPasswordActivity.class));
			break;
		case R.id.btn_more_updategesturepassword:
			startActivity(new Intent(this.getActivity(),UpdateGesturePasswordActivity.class));
			break;
		case R.id.btn_more_suggestionback:
			startActivity(new Intent(this.getActivity(),SuggestionFeedbackActivity.class));
			break;
		case R.id.btn_guest_switch :
			geust_switch = sp.getBoolean("guest_switch",false);
			geust_switch = geust_switch == true ? false
					: true;
			btn_guest_switch
			.setImageResource(geust_switch == true ? R.drawable.guesture_on
					: R.drawable.guesture_off);
			Editor editor = sp.edit();
			editor.putBoolean("guest_switch", geust_switch);
			editor.commit();
			break;
		default:
			break;
		}
	}
	
}
